using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Web.Core;

namespace Yuanlin.Business
{
    public class MemberServices : YuanlinUserControl,
        IReplyConverter<MemberServiceReply, GetListOperation>
    {
        protected Repeater listLeftMenuName;
        protected Repeater list;
        private EntityList memberServices;
        public int entityId = UrlManager.Instance.GetParameterValue<int>(YuanlinParameterName.MemberServiceId);

        public override void GetRequests(List<BaseRequestBinder> requestBinders)
        {
            requestBinders.Add(RequestHelper.BuildGetMemberServiceListRequest(this,0,100));
        }

        private void BindData()
        {
            if (list == null)
            {
                return;
            }

            listLeftMenuName.DataSource = memberServices;
            listLeftMenuName.DataBind();
            if (memberServices.Count == 0)
            {
                return;
            }

            EntityList entityList = new EntityList()  ;
            MemberService memberService = null;
            if (entityId == 0)
            {
                memberService = memberServices[0] as MemberService;
            }
            else
            {
                memberService = BusinessManager.GetMemberService(entityId);
                if (memberService == null)
                {
                    return;
                }
            }
            entityList.Add(memberService);
            list.DataSource = entityList;
            list.DataBind();
        }

        #region IReplyConverter<MemberServiceReply,GetListOperation> Members

        public void ConvertReply(MemberServiceReply reply, GetListOperation operation)
        {
            memberServices = reply.EntityList;

            if (!IsPostBack)
            {
                BindData();
            }
        }

        #endregion
    }
}